package cn.itsource.ymcc.producer;

import cn.itsource.ymcc.constant.CourseConstants;
import com.alibaba.fastjson.JSON;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.stereotype.Service;
import springfox.documentation.spring.web.json.Json;

import java.util.List;

@Service
public class CousreProducerImpl implements ICourseProducer{
    @Autowired
    private RocketMQTemplate rocketMQTemplate;

    @Override
    public void sendSMS(List<Long> courseIds) {
        rocketMQTemplate.sendOneWay(CourseConstants.TOPIC_COURSE_SMS_PUSH+":"+CourseConstants.TAGS_COURSE_SMS_PUSH,
                MessageBuilder.withPayload(JSON.toJSONString(courseIds)).build());
    }

    @Override
    public void sendEMAIL(List<Long> courseIds) {
        rocketMQTemplate.sendOneWay(CourseConstants.TOPIC_COURSE_EMAIL_PUSH+":"+CourseConstants.TAGS_COURSE_EMAIL_PUSH,
                MessageBuilder.withPayload(JSON.toJSONString(courseIds)).build());
    }

    @Override
    public void sendSYSTEM(List<Long> courseIds) {
        rocketMQTemplate.sendOneWay(CourseConstants.TOPIC_COURSE_SYSTEM_PUSH+":"+CourseConstants.TAGS_COURSE_SYSTEM_PUSH,
                MessageBuilder.withPayload(JSON.toJSONString(courseIds)).build());
    }

    @Override
    public void sendAll(List<Long> courseIds) {
        sendSMS(courseIds);
        sendEMAIL(courseIds);
        sendSYSTEM(courseIds);
    }
}
